﻿@{
    ViewBag.Title = "Index";
}
@using KingRoad.EPM.Common.Helper
<script type="text/javascript">
    var temp_Html_Permission_JLOperatorSet_Index_Segment_value = 0; //标段ID
    var Global_Permission_JLOperatorSet_Index_ContentHeight = 0;
    var htdType_JLOperatorSet_Index = 0; //标段类型
    var JLOperatorSet_ProjectID = 0;
    $(function () {
        //计算分栏高度
        Global_Permission_JLOperatorSet_Index_ContentHeight = $("#tabContent").innerHeight() - $(".panelBar",navTab.getCurrentPanel()).outerHeight();
        $("#Permission_JLOperatorSet_Index_div").height(Global_Permission_JLOperatorSet_Index_ContentHeight);

        //改变下拉框选项的事件处理
        $("#JLOperatorSet_HTType").change(function () {
            htdType_JLOperatorSet_Index = $(this).find("option:selected").val();
            zTreeSetting_JLOperatorSet();
            zTree_JLOperatorSet_Index = $("#tree_JLOperatorSet_Index").zTree(setting_JLOperatorSet_Index, zNodes_JLOperatorSet_Index);
            $("#Permission_JLOperatorSet_Index_Table").trigger("reloadGrid"); //重新加载JqGrid;
        });
        $("#JLOperatorSet_ProjType").change(function () {
            JLOperatorSet_ProjectID = $(this).find("option:selected").val();
            zTreeSetting_JLOperatorSet();
            zTree_JLOperatorSet_Index = $("#tree_JLOperatorSet_Index").zTree(setting_JLOperatorSet_Index, zNodes_JLOperatorSet_Index);
            temp_Html_Permission_JLOperatorSet_Index_Segment_value = 0;
            $("#Permission_JLOperatorSet_Index_Table").trigger("reloadGrid"); //重新加载JqGrid;
        });
    });
    var Permission_JLOperatorSet_save_StaffIDs = ""; //记录勾选的职员ID
    var Permission_JLOperatorSet_save_DutyIDs = ""; //记录勾选的岗位ID
    var Permission_JLOperatorSet_save_HTH = ""; //记录选择的标段编号
    var JLOperatorSet_selectHtName = "";
    var Global_Permission_JLOperatorSet_Index_Id = "0"; //列表项ID  
    var zNodes_JLOperatorSet_Index = [];
    var zTree_JLOperatorSet_Index;
    var setting_JLOperatorSet_Index;
    var JLOperatorSet_selectHtdid = 0;
    function zTreeSetting_JLOperatorSet() {
        setting_JLOperatorSet_Index = {
            checkable: false,
            async: true,
            isSimpleData: true,
            editable: false,
            asyncUrl: "/Permission/JLOperatorSet/GetAllSegment/" + htdType_JLOperatorSet_Index + "?projID=" + JLOperatorSet_ProjectID,  //获取节点数据的URL地址
            nameCol: "SEGMENT_CODE",
            treeNodeKey: "SEGMENT_ID",
            treeNodeParentKey: "ParentId",
            callback: {
                click: zTreeOnClick_JLOperatorSet_Index
            }
        };
    }
    //树的单击事件
    function zTreeOnClick_JLOperatorSet_Index(event, treeId, treeNode) {
        //获取所需要的主体
        temp_Html_Permission_JLOperatorSet_Index_Segment_value = treeNode.SEGMENT_ID;
        Permission_JLOperatorSet_save_HTH = treeNode.SEGMENT_CODE;
        Permission_JLOperatorSet_Prompt();
        Permission_JLOperatorSet_Index_ListTable_Load();
    }
    //------------------------------------------------
    //验证提示
    function Permission_JLOperatorSet_Prompt() {
        $.post("/Permission/JLOperatorSet/CheckData", { SegmentID: temp_Html_Permission_JLOperatorSet_Index_Segment_value, type: htdType_JLOperatorSet_Index }, function (json) {
            if (json.statusCode == "300") {
                if (json.date == null) {
                    alertMsg.info(json.message);
                    $("#Permission_JLOperatorSet_Index_Table").trigger("reloadGrid"); //重新加载JqGrid;
                }
            }
            else {
                $("#Permission_JLOperatorSet_Index_Table").trigger("reloadGrid"); //重新加载JqGrid;
            }
        });
    }
    //绑定列表数据
    function Permission_JLOperatorSet_Index_ListTable_Load() {
        $("#Permission_JLOperatorSet_Index_Table").jqGrid({
            url: "/Permission/JLOperatorSet/GetlistBySegmentID",
            datatype: "json",
            mtype: "post",
            colModel: [
                        { name: 'Id', index: 'Id', label: 'Id', width: 10, align: "center", sortable: false, hidden: true },
                        { name: 'DutyId', index: 'DutyId', label: 'DutyId', width: 10, align: "center", sortable: false, hidden: true },
                         { name: 'UserName', index: 'UserName', label: '用户名', width: 60, align: "left", sortable: false },
                        { name: 'RealName', index: 'RealName', label: '职员名称', width: 150, align: "left", sortable: false },
                        { name: 'DutyName', index: 'DutyName', label: '岗位名称', width: 200, align: "center", sortable: false },
                        { name: 'OrganizeName', index: 'OrganizeName', label: '公司名称', width: 120, align: "left", sortable: false }
                       ],
            beforeRequest: function (d) {
                $(this).jqGrid('setGridParam', { postData: { "SegmentID": temp_Html_Permission_JLOperatorSet_Index_Segment_value, "type": htdType_JLOperatorSet_Index} });
            },
            loadError: function (xhr, status) {
                alertMsg.error(xhr.responseText);
            },
            loadComplete: function (xhr) {
                var ajaxbg = $("#background,#progressBar,#lui_Permission_JLOperatorSet_Index_Table");
                ajaxbg.hide();
                Permission_JLOperatorSet_Index_ListTable_loadRow();
            },
            autowidth: true,
            rownumbers: true,
            shrinkToFit: true,
            multiselect: true,
            sortable: false,
            viewrecords: true,
            sortorder: "desc",
            jsonReader: {
                repeatitems: false
            },
            rowNum: -1,
            altRows: true,
            height: Global_Permission_JLOperatorSet_Index_ContentHeight - 23
        });
    }

    //勾选配置行
    function Permission_JLOperatorSet_Index_ListTable_loadRow() {
        var Permission_JLOperatorSet_jqGrid = $("#Permission_JLOperatorSet_Index_Table");
        $.post("/Permission/JLOperatorSet/CheckIsBeBySegmentIDAndStaffIDAndDutyID", { SegmentID: temp_Html_Permission_JLOperatorSet_Index_Segment_value, type: htdType_JLOperatorSet_Index }, function (json) {
            if (json.data != null) {
                for (var i = 0; i < Permission_JLOperatorSet_jqGrid[0].rows.length; i++) {
                    for (var j = 0; j < json.data.length; j++) {
                        if (json.data[j].HTDWFRELATION_DUTYID == Permission_JLOperatorSet_jqGrid.getCell(i, "DutyId") && json.data[j].HTDWFRELATION_STAFFID == Permission_JLOperatorSet_jqGrid.getCell(i, "Id")) {
                            Permission_JLOperatorSet_jqGrid.setSelection(i, false);
                        }
                    }
                }
            }
        });
    }
    //--------------------------------------------------------
    //保存事件
    function Permission_JLOperatorSet_Index_Create() {
        $("#Permission_JLOperatorSet_Index_Create").click(function () {
            var Permission_JLOperatorSet_jqGridObj = $("#Permission_JLOperatorSet_Index_Table");
            var selectHtdIds = Permission_JLOperatorSet_jqGridObj.jqGrid("getGridParam", "selarrrow");
            Permission_JLOperatorSet_save_StaffIDs = ""; Permission_JLOperatorSet_save_DutyIDs = "";
            if (selectHtdIds == "") {
                $.post("/Permission/JLOperatorSet/CreateJLOperatorSet", { SegmentID: temp_Html_Permission_JLOperatorSet_Index_Segment_value, type: htdType_JLOperatorSet_Index, SegmentCode: Permission_JLOperatorSet_save_HTH,
                    StaffIDs: Permission_JLOperatorSet_save_StaffIDs, DutyIDs: Permission_JLOperatorSet_save_DutyIDs
                }, function (json) {
                    if (json.statusCode == "300") {
                        if (json.date == null) {
                            $("#Permission_JLOperatorSet_Index_Table").trigger("reloadGrid"); //重新加载JqGrid;
                        }
                    }
                    else {
                        $("#Permission_JLOperatorSet_Index_Table").trigger("reloadGrid"); //重新加载JqGrid;
                    }
                    alertMsg.info(json.message);
                });
            } else {
                var SelectHtds_Array = selectHtdIds.toString().split(',');
                for (var i = 0; i < SelectHtds_Array.length; i++) {
                    var temp = "";
                    temp = Permission_JLOperatorSet_jqGridObj.getCell(parseInt(SelectHtds_Array[i]), "Id").toString(); //获取选中的职员ID
                    if (temp != "" && temp != "false") {
                        Permission_JLOperatorSet_save_StaffIDs += temp + ",";
                    }
                    temp = Permission_JLOperatorSet_jqGridObj.getCell(parseInt(SelectHtds_Array[i]), "DutyId").toString(); //获取选中的岗位ID
                    if (temp != "" && temp != "false") {
                        Permission_JLOperatorSet_save_DutyIDs += temp + ",";
                    }
                }
                $.post("/Permission/JLOperatorSet/CreateJLOperatorSet", { SegmentID: temp_Html_Permission_JLOperatorSet_Index_Segment_value, type: htdType_JLOperatorSet_Index, SegmentCode: Permission_JLOperatorSet_save_HTH,
                    StaffIDs: Permission_JLOperatorSet_save_StaffIDs, DutyIDs: Permission_JLOperatorSet_save_DutyIDs
                }, function (json) {
                    if (json.statusCode == "300") {
                        if (json.date == null) {
                            $("#Permission_JLOperatorSet_Index_Table").trigger("reloadGrid"); //重新加载JqGrid;
                        }
                    }
                    else {
                        $("#Permission_JLOperatorSet_Index_Table").trigger("reloadGrid"); //重新加载JqGrid;
                    }
                    alertMsg.info(json.message);
                });
            }
        });
    }
    //页面加载
    $(function () {
        temp_Html_Permission_JLOperatorSet_Index_Segment_value = "@ViewBag.SegmentID"; //默认选中第一标段
        Permission_JLOperatorSet_save_HTH = "@ViewBag.SegmentCode";
        JLOperatorSet_ProjectID = $("#JLOperatorSet_ProjType").val(); //项目ID
        htdType_JLOperatorSet_Index = 1;
        zTreeSetting_JLOperatorSet();
        zTree_JLOperatorSet_Index = $("#tree_JLOperatorSet_Index").zTree(setting_JLOperatorSet_Index, zNodes_JLOperatorSet_Index);
        
        Permission_JLOperatorSet_Index_Create();

    });
</script>
<div class="page">
    @*顶部按钮*@
    <div class="panelBar">
        <ul class="toolBar">
            <li id="li_JLOperatorSet_index" class="nobg">项目名称：@Html.DropDownList("JLOperatorSet_ProjType", new SelectList(ViewBag.ProjList as System.Collections.IEnumerable, "PRJINFO_ID", "PRJINFO_NAME"), new Dictionary<string, object> { { "style", "width:220px;" } })</li>
            <li id="li_JLOperatorSet_index" class="nobg">标段类型：@Html.DropDownList("JLOperatorSet_HTType", new SelectList(ViewBag.JLOperatorSet_HTTypeList as System.Collections.IEnumerable, "Flag", "Name"), new Dictionary<string, object> { { "style", "width:100px;" } })</li>
            <li>@Html.PermissionButton("Permission.JLOperatorSet.Index.Create", "Permission_JLOperatorSet_Index_Create", "add", "javascript:void(0)", "", "", "", "", "保存")</li>
        </ul>
    </div>
    <div id="Permission_JLOperatorSet_Index_div">
        <div id="Permission_JLOperatorSet_Index" class="leftPanel">
            @*标段列表*@
            <ul id="tree_JLOperatorSet_Index" class="ztree">
            </ul>
        </div>
        <div id="RightPanel_JLOperatorSet_Index" class="rightPanel">
            @*职员信息列表*@
            <table id="Permission_JLOperatorSet_Index_Table" >
            </table>
        </div>
    </div>
</div>
